import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { delCookie } from '../../../tools/util';
import { getUser } from '../../api/getUser';

class header extends Component{

    componentWillMount(){
        getUser();
    }

    signOut(){
        delCookie('u_name');
        delCookie('u_pw');
        window.location = '/';
    }

    render(){
        var { name } = this.props;
        return (
           <header id="header">
                <div id="user-name">
                    <i className="ic-svg ic-logo"></i>
                  { name } 的云笔记
                </div>
                <div id="person-center">
                    <span><i className="ic-svg ic-person"></i>个人中心</span>
                    <ul className="center-list">
                        <li><i className="ic-svg ic-set"></i>个人设置</li>
                        <li><a href="/recycle"><i className="ic-svg ic-reset"></i>回收站</a></li>
                        <li onClick={this.signOut.bind(this)}><i className="ic-svg ic-sign-out"></i>退出</li>
                    </ul>
                </div>
            </header>
        )
    }
}

const mapStateToProps  = (state) => {
    return {
        name: state.userInitState.name
    }
}

const mapDispatchToProps = (dispatch, ownProps) => {
    return {}
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(header);